<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>卡枚连&芭莎公益慈善晚宴签到</title>
	<meta name="description" content="">
	<meta http-equiv="X-UA-Compatible" content="chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"> 
	<meta name="apple-mobile-web-app-status-bar-style" content="black"> 
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link href="/plugins/layui/css/layui.css" type="text/css" rel="stylesheet">
	<script src="/plugins/layui/layui.js"></script>
	<script src="/assets/js/jquery-3.3.1.min.js"></script>
	<script src="/assets/js/windos.js"></script>
	<style type="text/css">
		.go {
			display: inline-block;
			width: 100px; 
			height: 100px; 
			line-height: 100px; 
			border-radius: 55px; 
			background: #0C0; 
			color: #FFF;
			font-size: 40px;
			border: 5px solid #9C9;
			margin-top: 40px;
			cursor: pointer;
		}
	</style>
</head>

<body>
<section class="main" style="text-align:center;margin-top: 30px;font-size: 48px;color: #ababab">
	邀 请 码
</section>
<form class="layui-form" action="" onsubmit="return false">
<section class="main" style="text-align:center;margin-top: 30px">
	<div class="layui-form-item" style="padding: 10px 0">
		<input type="text" name="token" lay-verify="token" autocomplete="off" class="layui-input" maxlength="4" style="font-size: 100px; color: #0C0;text-align: center;padding: 60px 0">
	</div>
	<div class="layui-block">
		<span name="view" class="go">GO</span>
	</div>
</section>
</form>

<script>
layui.use(['layer', 'jquery'], function() {
	var layer = layui.layer;
	var $ = layui.$;
	$('span[name="view"]').bind('touchend', function(event) {
		var input = $('input[name="token"]');
		var othis = $(this);
		
		var len = input.val().length;
		
		var btnText = {
			confirm: '确认签到',
			unconfirm: '取消签到',
			close: '关闭',
			lock: '确认锁定',
			unlock: '取消锁定'
		}
		
		
			if (len == 4) {
				windos.ajaxPost('/site/get_profile', {t: input.val()}, function(res) {
					var btnText1 = res.data.status == 1 ? btnText.unconfirm : btnText.confirm;
					var btnText2 = btnText.close;
					var btnText3 = res.data.status == 2 ? btnText.unlock : btnText.lock;
					var btns = [btnText1, btnText2, btnText3];
					if (typeof(res.data) === 'object') {
						layer.open({
							type: 1,
							offset: 'auto',
							id: 'view',
							area: ['360px', '480px'], //宽高
							shade: 0,
							closeBtn: false,
							btn: btns,
							btnAlign: 'c',
							title: '个人资料',
							content: '<table class="layui-table" lay-skin="line">\
							<colgroup><col width="30%"><col width="70%"></colgroup>\
							<tbody>\
								<tr><td align="right">姓名：</td><td>' + windos.formatText(res.data.name) + '</td></tr>\
								<tr style="display: none"><td align="right">性别：</td><td>' + (res.data.gender ? '男' : '女') + '</td></tr>\
								<tr><td align="right">桌号：</td><td>' + windos.formatText(res.data.tnumber) + '</td></tr>\
								<tr><td align="right">手机号：</td><td>' + windos.formatMobile(res.data.mobile, 0) + '</td></tr>\
								<tr><td align="right">邀请人：</td><td>' + windos.formatText(res.data.inviter) + '</td></tr>\
								<tr><td align="right">当前状态：</td><td>' + formatStatus(res.data.status) + '</td></tr>\
								<tr><td align="right">邀请码：</td><td>' + res.data.token + '</td></tr>\
								<tr><td align="right">操作时间：</td><td>' + windos.formatDate(res.data.edit_time, 0) + '</td></tr>\
								<tr><td align="right">确认时间：</td><td>' + windos.formatDate(res.data.confirm_time, 0) + '</td></tr>\
							<tbody>\
							</table>',
							btn1: function() {
								var value = res.data.status != 1 ? 1 : 0;
								windos.ajaxPost('/site/save', {id: res.data.id, field: 'status', value: value}, function(res2){
									console.log(res2);
								});
								layer.closeAll();
							},
							btn2: function() {
								layer.closeAll();
							},
							btn3: function() {
								var value = res.data.status != 2 ? 2 : 0;
								windos.ajaxPost('/site/save', {id: res.data.id, field: 'status', value: value}, function(res2){
									console.log(res2);
								});
								layer.closeAll();
							},
							success: function(layero) {
								
								var btn = layero.find('.layui-layer-btn');
								btn.find('.layui-layer-btn2').css({'background-color': '#FF5722', 'color': '#FFF'});
							}
						});
					} else {
						layer.msg('无效的邀请码', {icon: 5});
					}
					//console.log(res);
				});
			} else {
				layer.msg('输入4位数邀请码', {icon: 5});
			}
			
		
		
	});
	
	$('input[name="token"]').bind('focus', function() {
		var othis = $(this);
		othis.val('');
	}).bind('blur', function() {
		$('span[name="view"]').trigger('touchend');
	});
	
	function formatStatus(code) {
		var res = '<span style="color:#F60">未签到</span>';
		switch(code) {
			case 1:
				res = '<span style="color:#0C0">已签到</span>';
			break;
			case 2:
				res = '<span style="color:#F00">已锁定</span>';
			break;
		}
		return res;
	}
});
	
</script>
</body>
</html>
